package com.yunxi.service.dubboService.impl.sys;

import com.github.pagehelper.PageInfo;
import com.yunxi.model.sys.Dict;
import com.yunxi.service.localService.sys.DictService;
import com.yunxi.bizToBaseData.pojo.DictVO;
import com.yunxi.sys.service.DictDubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-05-08
 */
public class DictDubboServiceImpl implements DictDubboService {

    @Autowired
    @Qualifier(value = "dictServiceImpl")
    DictService dictService;


    @Override
    public DictVO getById(String id) throws InvocationTargetException, IllegalAccessException {
    Dict dict = dictService.getById(id);
    DictVO dictVO = new DictVO();
        BeanUtils.copyProperties(dict,dictVO);
        return dictVO;
    }

    @Override
    public void saveOrUpdate(DictVO dictVO) throws InvocationTargetException, IllegalAccessException {
    Dict dict = new Dict();
        BeanUtils.copyProperties(dictVO,dict);
    dictService.saveOrUpdate(dict);
    }

    @Override
    public void removeById(String id) {
    dictService.removeById(id);
    }

    @Override
    public PageInfo<DictVO> findPageByVO(DictVO dictVo, Integer pageNum, Integer pageSize) throws InvocationTargetException, IllegalAccessException {

      PageInfo<DictVO> dictList = dictService.pageByVo(dictVo,pageNum,pageSize);

      //PageInfo<DictVO> dictVOList = new PageInfo<>();
      //BeanUtils.copyProperties(dictList,dictVOList);

      return dictList;

   }

    @Override
    public DictVO loadCas(String dictId) {
        return dictService.loadCas(dictId);
    }

    @Override
    public void saveBatch(DictVO dictVO) {
        dictService.saveBatchCas(dictVO);
    }

    @Override
    public void delCas(List<DictVO> dictList) {
        dictService.delCas(dictList);
    }

    @Override
    @Cacheable(value="dicts",key = "'dict:list_key_'+#type")
    public List listByType(String type) {
        return dictService.listByType(type);
    }

    @Override
    //@Cacheable(value="dicts",key = "'pms_dict_all'")
    public Map listAll() {
        return dictService.listAll();
    }

    @Override
    public List listBySat() {
        return dictService.listBySat();
    }
}
